<template>
  <div class="U0000024-template1" :class="className">
    <!-- style -->
    <div v-html="css"></div>

    <!--微社区静态-->
    <div id="community" v-if="datas.preview_color">
      <div class="nav nav-bgimage" v-if="!datas.notShowTab && datas.get_style == 1">
        <div class="nav-li nav-selected">
          <div class=" nav-lis">最新</div>
        </div>
        <div class="nav-li" v-if="datas.show_nearby">
          <div class="nav-lis">附近</div>
        </div>
        <div class="nav-li">
          <div class="nav-lis">分类1</div>
        </div>
        <div class="nav-li">
          <div class="nav-lis">分类2</div>
        </div>
      </div>
      <div class="list" v-if="datas.show_template == '1'">
        <div class="list_child" v-for="item in 2">
          <img src="../../../resource/images/empty-preview.png" alt="" class="img" />
          <div class="bottom_box">
            <p class="title">帖子标题</p>
            <div class="other">
              <div class="user_info">
                <img src="../../../resource/images/image.png" alt="" class="user_Avatar" />
                <div class="user_name">用户昵称</div>
              </div>
              <div class="like_box">
                <i class="iconfont icon-card_laud"></i>
                <div class="num">145</div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div id="micro-communities" v-if="datas.show_template == '2'">
        <div class="post-item" v-for="(item, i) in 2" :key="i">
          <div class="post-header">
            <img src="../../../resource/images/image.png" alt=""/>
            <div class="post-author">
              <div>用户昵称</div>
              <div class="post-created-time">2020-05-20</div>
            </div>
          </div>
          <div class="post-body">
            <div class="post-title">帖子标题</div>
            <div class="post-content">帖子内容帖子内容帖子内容帖子内容帖子内容帖子内容帖子内容帖子内容</div>
            <div class="post-images post-images-multi">
              <img v-for="(chi, itemIndex) in 2" :key="itemIndex" src="../../../resource/images/empty-preview.png" alt="" class="post-image-item"/>
            </div>
          </div>
          <div class="post-footer">
            <ul class="post-statistics">
              <li class="post-statistics-item">
                <i class="post-statistics-icon iconfont icon-fontclass-yulan"></i>
                99
              </li>
              <li class="post-statistics-item">
                <i class="post-statistics-icon iconfont icon-fontclass-dianzan"></i>
                99
              </li>
              <li class="post-statistics-item">
                <i class="post-statistics-icon iconfont icon-fontclass-pinglun1"></i>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// 自定义样式
const css = function() {
  if (this.datas.preview_color) {
    const { preview_color, tab_bg, title_color, title_active_color } = this.datas;

    return `
        .component-${this.id} .list, .component-${this.id} #micro-communities{
            background-color: ${preview_color};
        }

        .component-${this.id} .nav-bgimage {
            background-color: ${tab_bg};
        }

        .component-${this.id} .nav-li {
            color: ${title_color};
        }

        .component-${this.id} .nav-li.nav-selected {
            color: ${title_active_color};
            border-bottom: solid  2px ${title_active_color};
        }
    `;
  }
};

export default {
  props: ["id", "datas", "styles"],
  data() {
    return {};
  },
  mounted() {},
  computed: {
    css() {
      return "<style>" + css.call(this) + "</style>";
    },
    className() {
      const name = ["component-wrapper", `component-${this.id}`];
      return name;
    },
  },
  watch: {},

  methods: {},
};
</script>

<style lang="less" scoped>
// 默认
.component-wrapper {
  display: flex;
  justify-content: center;
  width: 375px;
}
#community {
  width: 100%;
  .nav {
    display: flex;
    align-items: center;
    height: 40px;
    white-space: nowrap;
    flex-wrap: nowrap;
    box-sizing: content-box;
    .nav-li {
      flex: 1;
      min-width: 20%;
      text-align: center;
      .nav-lis {
        display: inline-block;
        line-height: 40px;
      }
    }
    .nav-selected {
      /*border-bottom: 2px solid #333;*/
    }
  }

  .scroll {
    overflow-x: scroll;
  }
  .list {
    width: 100%;
    padding: 10px 12px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    .list_child {
      width: 170px;
      display: flex;
      flex-direction: column;
      background: #fff;
      border-radius: 5px;
      overflow: hidden;
      .img {
        width: 170px;
        height: 170px;
      }
      .bottom_box {
        padding: 10px;
        .title {
          font-size: 14px;
          color: #333;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        .other {
          display: flex;
          justify-content: space-between;
          align-items: center;
          .user_info {
            display: flex;
            justify-content: space-between;
            align-items: center;
            .user_Avatar {
              width: 18px;
              height: 18px;
              border-radius: 100%;
              margin-right: 6px;
            }
            .user_name {
              width: 50px;
              color: #8c8c8c;
              font-size: 11px;
              overflow: hidden; /*超出部分隐藏*/
              text-overflow: ellipsis; /* 超出部分显示省略号 */
              white-space: nowrap; /*规定段落中的文本不进行换行 */
            }
          }
          .like_box {
            display: flex;
            justify-content: space-between;
            align-items: center;
            color: #333333;
            font-size: 12px;
          }
        }
      }
    }
  }

  #micro-communities {
    padding: 10px 14px;
  }
  .h-625 {
    height: 10px;
  }
  .post-item {
    margin-bottom: 10px;
    padding: 15px;
    text-align: left;
    background-color: white;
    border-radius: 8px;
  }

  .post-header {
    display: grid;
    align-items: center;
    grid-template-columns: 40px 160px auto;
    width: 100%;
    img{
      width: 40px;
      height: 40px;
      border-radius: 50%;
    }
  }

  .post-author {
    margin-left: 8px;
    font-size: 15px;
    color: #333;
  }

  .post-created-time {
    font-size: 12px;
    color: #999;
  }

  .post-operator {
    justify-self: end;
  }

  .post-body {
    margin-top: 18px;
  }

  .post-title {
    font-size: 16px;
    color: #202020;
    word-break: break-all;
  }

  .post-content {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    text-overflow: ellipsis;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-top: 14px;
    line-height: 18px;
    color: #868585;
    word-break: break-all;
  }

  .post-images {
    margin-top: 10px;
  }

  .post-images-multi {
    display: grid;
    grid-template-columns: repeat(3, 100px);
    column-gap: 10px;
    row-gap: 10px;
    position: relative;
    padding: 0;
  }

  .post-image-item {
    width: 100%;
    max-width: 60%;
    max-height: 250px;
    border-radius: 8px;
  }

  .post-images-multi .post-image-item {
    height: 100px;
    max-height: unset;
    max-width: unset;
  }

  .post-view-more {
    position: absolute;
    right: 0;
    bottom: 0;
    height: 100px;
    line-height: 100px;
    width: 100px;
    text-align: center;
    color: white;
    font-size: 14px;
    font-weight: bold;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 8px;
    cursor: pointer;
  }

  .post-footer {
    margin-top: 8px;
  }

  .post-circle {
    display: inline-flex;
    align-items: center;
    padding: 4px 15px 4px 4px;
    color: #6d99f3;
    background-color: #f1f6ff;
    border-radius: 8px;
  }

  .post-circle-icon {
    width: 15px;
    height: 15px;
  }

  .post-circle-name {
    margin-left: 4px;
    max-width: 110px;
    overflow: hidden;
    font-size: 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .post-statistics {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-top: 8px;
    font-size: 10px;
    color: #7c7c7c;
  }
  li{
    list-style: none;
  }

  .post-statistics-item {
    margin-left: 12px;
  }

  .post-statistics-item-active {
    color: #3175fe;
  }
}
</style>
